package com.example.newspublish.controller;

import com.example.newspublish.pojo.entity.SysMenu;
import com.example.newspublish.pojo.result.Result;
import com.example.newspublish.service.SysMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name="菜单管理")
@RestController
@RequestMapping("/news")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    //添加菜单
    @Operation(summary = "添加菜单", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("sysMenusave")
    public Result save(@RequestBody SysMenu sysMenu) {
        sysMenuService.save(sysMenu);
        return Result.ok();
    }

    @Operation(summary = "根据id查询菜单", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("findMenuNode/{id}")
    public Result findNode(@PathVariable String id) {
        SysMenu sysMenu = sysMenuService.getById(id);
        return  Result.ok(sysMenu);
    }

    //修改
    @Operation(summary = "修改菜单", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("sysMenuUpdate")
    public Result update(@RequestBody SysMenu sysMenu) {
        sysMenuService.updateById(sysMenu);
        return Result.ok();
    }

    //删除菜单
    @Operation(summary = "删除菜单", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("menuRemove/{id}")
    public Result remove(@PathVariable String id) {
        sysMenuService.removeById(id);
        return Result.ok();
    }

}
